﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using OTS.BLL;
using OTS.Model;

public partial class Templates_top : System.Web.UI.MasterPage
{
    protected string placard0;
    protected string placard1;
    protected string placard2;
    protected string placard3;
    protected string placard4;

    protected void Page_Load(object sender, EventArgs e)
    {
        PlacardBLL plaBLL = new PlacardBLL();
        custom cus = new custom();
        ProductTypeBLL proType = new ProductTypeBLL();
        DataTable dt = plaBLL.GetByPla();
        DataTable table = proType.GetAllType();

        this.rpType.DataSource = table;
        this.rpType.DataBind();

        if (Session["custom"]!=null)
        {
            cus = (custom)Session["custom"];
            this.lblShowUser.Text = "您好，" + cus.cusLoginName + "，欢迎光临贵美依！";
            this.panelCkLogin.Visible = false;
        }
        else
        {
            this.panelLogin.Visible = false;
        }
        
        int plaCount = dt.Rows.Count;
        if (plaCount > 0)
        {
            if (dt.Rows[0]["plaType"].ToString() == "0") //取自自定义
            {
                placard0 = "<a href='./Placard.aspx?id=" + dt.Rows[0]["plaID"].ToString() + "'>" + dt.Rows[0]["plaTitle"].ToString() + "</a>";
            }
            else
            {
                placard0 = "<a href='./" + dt.Rows[0]["plaURL"].ToString() + "'>" + dt.Rows[0]["plaTitle"].ToString() + "</a>";
            }
        }
        if (plaCount > 1)
        {
            if (dt.Rows[1]["plaType"].ToString() == "0") //取自自定义
            {
                placard1 = "<a href='./Placard.aspx?id=" + dt.Rows[1]["plaID"].ToString() + "'>" + dt.Rows[1]["plaTitle"].ToString() + "</a>";
            }
            else
            {
                placard1 = "<a href='./" + dt.Rows[1]["plaURL"].ToString() + "'>" + dt.Rows[1]["plaTitle"].ToString() + "</a>";
            }
        }
        if (plaCount > 2)
        {
            if (dt.Rows[2]["plaType"].ToString() == "0") //取自自定义
            {
                placard2 = "<a href='./Placard.aspx?id=" + dt.Rows[2]["plaID"].ToString() + "'>" + dt.Rows[2]["plaTitle"].ToString() + "</a>";
            }
            else
            {
                placard2 = "<a href='./" + dt.Rows[2]["plaURL"].ToString() + "'>" + dt.Rows[2]["plaTitle"].ToString() + "</a>";
            }
        }
        if (plaCount > 3)
        {
            if (dt.Rows[3]["plaType"].ToString() == "0") //取自自定义
            {
                placard3 = "<a href='./Placard.aspx?id=" + dt.Rows[3]["plaID"].ToString() + "'>" + dt.Rows[3]["plaTitle"].ToString() + "</a>";
            }
            else
            {
                placard3 = "<a href='./" + dt.Rows[3]["plaURL"].ToString() + "'>" + dt.Rows[3]["plaTitle"].ToString() + "</a>";
            }
        }
        if (plaCount > 4)
        {
            if (dt.Rows[4]["plaType"].ToString() == "0") //取自自定义
            {
                placard4 = "<a href='./Placard.aspx?id=" + dt.Rows[4]["plaID"].ToString() + "'>" + dt.Rows[4]["plaTitle"].ToString() + "</a>";
            }
            else
            {
                placard4 = "<a href='./" + dt.Rows[4]["plaURL"].ToString() + "'>" + dt.Rows[4]["plaTitle"].ToString() + "</a>";
            }
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        if (this.txtName.Text!="")
        {
            Response.Redirect("gallery-grid.aspx?name=" + this.txtName.Text);
        }
        else if (this.txtPrice1.Text!="")
        {
            Response.Redirect("gallery-grid.aspx?price1=" + this.txtPrice1.Text);
        }
        else if (this.txtPrice2.Text!="")
        {
            Response.Redirect("gallery-grid.aspx?price2=" + this.txtPrice2.Text);
        }
        else if (this.txtName.Text!="" && this.txtPrice1.Text!="")
        {
            Response.Redirect("gallery-grid.aspx?name=" + this.txtName.Text + "&price1=" + this.txtPrice1.Text);
        }
        else if (this.txtName.Text!="" && this.txtPrice2.Text!="")
        {
            Response.Redirect("gallery-grid.aspx?name=" + this.txtName.Text + "&price2=" + this.txtPrice2.Text);
        }
        else if (this.txtName.Text!="" && this.txtPrice1.Text!="" && this.txtPrice2.Text!="")
        {
            Response.Redirect("gallery-grid.aspx?name=" + this.txtName.Text + "&price1=" + this.txtPrice1.Text + "&price2=" + this.txtPrice2.Text);
        }
        else
        {
            Response.Redirect("gallery-grid.aspx");
        }
    }
    protected void lbtnExit_Click(object sender, EventArgs e)
    {
        Session.RemoveAll();
        Response.Redirect("index.aspx");
    }
}
